﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace xiaodingmarket_service.Migrations
{
    public partial class init : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "commodities",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    Kind = table.Column<int>(nullable: true),
                    Category = table.Column<int>(nullable: false),
                    wanter = table.Column<int>(nullable: false),
                    ViewsCount = table.Column<int>(nullable: false),
                    endtime = table.Column<DateTime>(type: "DATETIME2", nullable: true),
                    Remark = table.Column<string>(type: "varchar(500)", nullable: true),
                    Wanterid = table.Column<string>(type: "varchar(500)", nullable: true),
                    State = table.Column<int>(nullable: false),
                    IsDelete = table.Column<bool>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_commodities", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "module",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    Name = table.Column<string>(type: "varchar(200)", nullable: true),
                    Url = table.Column<string>(type: "varchar(200)", nullable: true),
                    ParentCode = table.Column<string>(type: "varchar(200)", nullable: true),
                    remark = table.Column<string>(type: "varchar(500)", nullable: true),
                    LogTime = table.Column<DateTime>(nullable: false),
                    ModifyTime = table.Column<DateTime>(nullable: false),
                    CreateUserId = table.Column<Guid>(nullable: false),
                    ModifyUserId = table.Column<Guid>(nullable: false),
                    IsDelete = table.Column<bool>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_module", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "orderCommodities",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    Buyer = table.Column<Guid>(nullable: false),
                    Seller = table.Column<Guid>(nullable: false),
                    Condition = table.Column<int>(nullable: false),
                    LogTime = table.Column<DateTime>(nullable: false),
                    ModifyTime = table.Column<DateTime>(nullable: false),
                    CreateUserId = table.Column<Guid>(nullable: false),
                    ModifyUserId = table.Column<Guid>(nullable: false),
                    Remark = table.Column<string>(type: "varchar(500)", nullable: true),
                    Address = table.Column<string>(type: "varchar(200)", nullable: true),
                    IsDelete = table.Column<bool>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_orderCommodities", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "reports",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    reportkind = table.Column<int>(nullable: false),
                    reporter = table.Column<Guid>(nullable: false),
                    bereporter = table.Column<Guid>(nullable: false),
                    Reason = table.Column<string>(type: "varchar(500)", nullable: true),
                    LogTime = table.Column<DateTime>(nullable: false),
                    ModifyTime = table.Column<DateTime>(nullable: false),
                    CreateUserId = table.Column<Guid>(nullable: false),
                    ModifyUserId = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_reports", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "role",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    Name = table.Column<string>(type: "varchar(100)", nullable: true),
                    remark = table.Column<string>(type: "varchar(200)", nullable: true),
                    LogTime = table.Column<DateTime>(nullable: false),
                    ModifyTime = table.Column<DateTime>(nullable: false),
                    CreateUserId = table.Column<Guid>(nullable: false),
                    ModifyUserId = table.Column<Guid>(nullable: false),
                    IsDelete = table.Column<bool>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_role", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "user",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    StudentId = table.Column<string>(type: "varchar(200)", nullable: true),
                    StudentName = table.Column<string>(type: "varchar(100)", nullable: true),
                    StudentSex = table.Column<string>(type: "varchar(50)", nullable: true),
                    collegename = table.Column<string>(type: "varchar(100)", nullable: true),
                    Userid = table.Column<string>(type: "varchar(100)", nullable: true),
                    UserName = table.Column<string>(type: "varchar(100)", nullable: true),
                    UserPictureSrc = table.Column<string>(type: "varchar(100)", nullable: true),
                    email = table.Column<string>(type: "varchar(50)", nullable: true),
                    Pwd = table.Column<string>(type: "varchar(50)", nullable: true),
                    LastLoginTime = table.Column<DateTime>(nullable: false),
                    LogTime = table.Column<DateTime>(nullable: false),
                    ModifyTime = table.Column<DateTime>(nullable: false),
                    CreateUserId = table.Column<string>(nullable: true),
                    ModifyUserId = table.Column<string>(nullable: true),
                    IsDelete = table.Column<bool>(nullable: false),
                    remark = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_user", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "commodityDetails",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CommodityId = table.Column<Guid>(nullable: false),
                    Detile = table.Column<string>(type: "varchar(500)", nullable: true),
                    Title = table.Column<string>(type: "varchar(200)", nullable: false),
                    Thumbnail = table.Column<string>(type: "varchar(500)", nullable: true),
                    Img = table.Column<string>(nullable: true),
                    Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    LogTime = table.Column<DateTime>(nullable: false),
                    ModifyTime = table.Column<DateTime>(nullable: false),
                    StudentId = table.Column<Guid>(nullable: false),
                    ModifyId = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_commodityDetails", x => x.Id);
                    table.ForeignKey(
                        name: "FK_commodityDetails_commodities_Id",
                        column: x => x.Id,
                        principalTable: "commodities",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "orderDetails",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    Productid = table.Column<Guid>(nullable: false),
                    price = table.Column<decimal>(type: "decimal(18,2)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_orderDetails", x => x.Id);
                    table.ForeignKey(
                        name: "FK_orderDetails_orderCommodities_Id",
                        column: x => x.Id,
                        principalTable: "orderCommodities",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "reportprocesses",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    Productid = table.Column<Guid>(nullable: false),
                    Result = table.Column<string>(type: "varchar(200)", nullable: true),
                    ProcessTime = table.Column<DateTime>(nullable: false),
                    Evaluation = table.Column<string>(type: "varchar(500)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_reportprocesses", x => x.Id);
                    table.ForeignKey(
                        name: "FK_reportprocesses_reports_Id",
                        column: x => x.Id,
                        principalTable: "reports",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "moduleRoles",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    ModuleID = table.Column<Guid>(nullable: false),
                    RoleID = table.Column<Guid>(nullable: false),
                    IsDelete = table.Column<bool>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_moduleRoles", x => x.Id);
                    table.ForeignKey(
                        name: "FK_moduleRoles_module_ModuleID",
                        column: x => x.ModuleID,
                        principalTable: "module",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_moduleRoles_role_RoleID",
                        column: x => x.RoleID,
                        principalTable: "role",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "UserRoles",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    UserID = table.Column<Guid>(nullable: false),
                    RoleID = table.Column<Guid>(nullable: false),
                    IsDelete = table.Column<bool>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_UserRoles", x => x.Id);
                    table.ForeignKey(
                        name: "FK_UserRoles_role_RoleID",
                        column: x => x.RoleID,
                        principalTable: "role",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_UserRoles_user_UserID",
                        column: x => x.UserID,
                        principalTable: "user",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_commodities_Category",
                table: "commodities",
                column: "Category");

            migrationBuilder.CreateIndex(
                name: "IX_moduleRoles_ModuleID",
                table: "moduleRoles",
                column: "ModuleID");

            migrationBuilder.CreateIndex(
                name: "IX_moduleRoles_RoleID",
                table: "moduleRoles",
                column: "RoleID");

            migrationBuilder.CreateIndex(
                name: "IX_UserRoles_RoleID",
                table: "UserRoles",
                column: "RoleID");

            migrationBuilder.CreateIndex(
                name: "IX_UserRoles_UserID",
                table: "UserRoles",
                column: "UserID");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "commodityDetails");

            migrationBuilder.DropTable(
                name: "moduleRoles");

            migrationBuilder.DropTable(
                name: "orderDetails");

            migrationBuilder.DropTable(
                name: "reportprocesses");

            migrationBuilder.DropTable(
                name: "UserRoles");

            migrationBuilder.DropTable(
                name: "commodities");

            migrationBuilder.DropTable(
                name: "module");

            migrationBuilder.DropTable(
                name: "orderCommodities");

            migrationBuilder.DropTable(
                name: "reports");

            migrationBuilder.DropTable(
                name: "role");

            migrationBuilder.DropTable(
                name: "user");
        }
    }
}
